component extends="Model" output="false" {

	public void function init() {
	  belongsTo('team_player');
	}

	public function runStaticBulkQuery(q)
	{
		var loc = {};
		loc.queryService = new Query();
		loc.queryService.setName('runStaticBulkQuery');
		loc.queryService.setDatasource(get('dataSourceName'));
		loc.result = loc.queryService.execute(sql=q);
		return;
	}

	public function getPlayersByFixtureId(fixtureId)
	{
		var loc = {};
		loc.queryService = new Query();
		loc.queryService.setName('getPlayersByFixtureId');
		loc.queryService.setDatasource(get('dataSourceName'));
		loc.result = loc.queryService.execute(sql="
SELECT p.first_name + ' ' + p.last_name + ' (' + c.name + ')' as 'fullnameclub', p.id, p.first_name, p.last_name, p.avg_fantasy_points, c.name FROM players p WITH (NOLOCK) 
INNER JOIN clubs c WITH (NOLOCK) ON p.clubid = c.id
WHERE c.id IN
(
	SELECT home_club_id FROM fixtures
	WHERE id = #arguments.fixtureId#
	UNION ALL
	SELECT away_club_id FROM fixtures
	WHERE id = #arguments.fixtureId#
)
ORDER BY p.clubid, p.first_name, p.last_name
		");
		return loc.result.getResult();
	}

}
